/**
 * fulihui.com Inc.
 * Copyright (c) 2015-2016 All Rights Reserved.
 */
package com.fulihui.wgj.config;

import com.fulihui.wgj.config.properties.ThreadPoolProps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 初始化spring
 *
 * @author wang_wx
 * @date 2018-06-20
 */
@Configuration
@EnableConfigurationProperties({ThreadPoolProps.class})
public class ThreadPoolConfig {

    @Autowired
    ThreadPoolProps threadPoolProps;

    @Bean
    public ThreadPoolTaskExecutor threadPool() {
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        threadPool.setCorePoolSize(threadPoolProps.getCorePoolSize());
        threadPool.setMaxPoolSize(threadPoolProps.getMaxPoolSize());
        threadPool.initialize();
        return threadPool;
    }

}
